package com.yyj.dao;

import com.yyj.entity.Audit;
import com.yyj.entity.Params;
import com.yyj.entity.Pet;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AuditDao {
    @Insert("insert into audit(id, applyUserId,petId,applyTime,applyStatus,setTime,applyReason,okTime,reply,contact,spot,progress) values (#{id},#{applyUserId},#{petId},now(),'待审核',#{setTime},#{applyReason},#{okTime},#{reply},#{contact},#{spot},'1')")
    void add(Audit audit);

    List<Audit> getBySearch(@Param("params") Params params);

    //用户查自己发布的领养申请
    @Select("select audit.*,pet.* from audit left join pet on audit.petId=pet.petId where applyUserId=#{applyUserId}")
    List<Audit> getMyAudit(Integer applyUserId);

    //用户通过领养申请查自己想要领养的宠物
    @Select("select audit.*,pet.* from audit left join pet on audit.petId=pet.petId where audit.petId=#{petId}")
    Audit getAPet(Integer petId);

    @Update("update audit set applyStatus=#{applyStatus},reply=#{reply},okTime=now(),progress=#{progress} where id=#{id}")
    void check(Audit audit);

    @Delete("DELETE FROM audit WHERE id = #{id}")
    void delete(Integer auditId);

    @Update("update audit set contact=#{contact},setTime=#{setTime},spot=#{spot},applyReason=#{applyReason}")
    void update(Audit audit);

    @Select("SELECT audit.*, user.*, pet.* FROM audit LEFT JOIN user ON audit.applyUserId = user.userId LEFT JOIN pet ON audit.petId = pet.petId where originalOwnerId=#{originalOwnerId}")
    List<Audit> getReceive(Integer originalOwnerId);

    @Update("update pet set status='已被领养',newOwner=#{newOwner} where petId=#{petId} ")
    void setPet(Pet pet);
    @Update("update audit set progress='3'")
    void setProgress();
}
